<?php
declare (strict_types=1);

namespace app\common\controller;

use app\common\model\Account;
use app\common\model\Logs;
use app\common\model\Relation;
use app\common\model\User;
use app\common\model\UserNode;

class Bonus
{

    public static function platoonBonus($user, $order): array
    {
        try {
            $pUser = User::find($user->parent_id);
            if($pUser->platoon_id == 1){
                $ztCount = $pUser->push_num;
                switch ($ztCount){
                    case 2:
                        Account::bonusEntry($pUser->id, 1500, 'VIP分红', $user->id, 1, $order->id);
                        break;
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                        if($ztCount == 3){
                            UserNode::joinPlatoon($pUser,$order);
                        }
                        $childNodeCount = User::where('node_id', $pUser->id)->count();
                        if($childNodeCount < 1){
                            return ['code'=>1, 'msg'=>'success'];
                        }
                        Account::bonusEntry($pUser->id, 1500, 'VIP分红', $user->id, 1, $order->id);
                        break;
                    default:
                        break;
                }
            }
            return ['code'=>1, 'msg'=>'success'];
        } catch (\Exception $e) {
            Logs::exception($e);
            return ['code'=>-1, 'msg'=>$e->getMessage()];
        }
    }
}